package io.github.chutian0610.sqlparser.token

import io.github.chutian0610.sqlparser.Location
import io.kotest.core.spec.style.StringSpec
import io.kotest.matchers.shouldBe

class CharStreamTest : StringSpec({
    "CharStream next() should consume char" {
        val codePointCharStream = CodePointCharStream.fromString("hello")
        codePointCharStream.next() shouldBe CodePoint.fromChar('h')
        codePointCharStream.next() shouldBe CodePoint.fromChar('e')
        codePointCharStream.next() shouldBe CodePoint.fromChar('l')
        codePointCharStream.next() shouldBe CodePoint.fromChar('l')
        codePointCharStream.next() shouldBe CodePoint.fromChar('o')
        codePointCharStream.next() shouldBe (null)
    }
    "CharStream peek() should not consume char" {
        val codePointCharStream = CodePointCharStream.fromString("hello")
        codePointCharStream.peek() shouldBe CodePoint.fromChar('h')
        codePointCharStream.peek() shouldBe CodePoint.fromChar('h')
    }
    "CharStream location() should return location" {
        val codePointCharStream = CodePointCharStream.fromString("hello\nworld")
        codePointCharStream.location() shouldBe (Location(1, 0))
        codePointCharStream.next() shouldBe CodePoint.fromChar('h')
        codePointCharStream.next() shouldBe CodePoint.fromChar('e')
        codePointCharStream.next() shouldBe CodePoint.fromChar('l')
        codePointCharStream.next() shouldBe CodePoint.fromChar('l')
        codePointCharStream.next() shouldBe CodePoint.fromChar('o')
        codePointCharStream.location() shouldBe (Location(1, 5))
        codePointCharStream.next() shouldBe CodePoint.fromChar('\n')
        codePointCharStream.location() shouldBe (Location(2, 0))
    }
})